﻿
using System;
using System.Collections.Generic;
namespace Wicresoft.UnifyShow.Business
{
    public interface IPlanManagement
    {
        bool SaveJob(ScheduleJob scheduleJob);

        /// <summary>
        /// 检查计划名重复
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="expectID">不与该ID的Name进行检查</param>
        /// <returns></returns>
        bool IsJobNameExisted(string jobName, decimal? expectID);

        /// <summary>
        /// 获取计划详情
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        ScheduleJob GetScheduleJobDetail(decimal ID);

        /// <summary>
        /// 获取任务详情 
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        TaskModel GetTaskDetail(decimal ID);

        /// <summary>
        /// 获取任务或计划上传的文件列表
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        List<TaskAttachmentModel> GetFileList(decimal RelationID);

        /// <summary>
        /// 根据GID获取计划对应的文件列表
        /// </summary>
        /// <param name="GID"></param>
        /// <returns></returns>
        List<TaskAttachmentModel> GetFileListByGID(string GID);

        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        bool AddFile(TaskAttachmentModel file);

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="FileID"></param>
        /// <returns></returns>
        bool DeleteFile(int FileID);

        /// <summary>
        /// 获取文件详情
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        TaskAttachmentModel GetFileByID(int ID);

        /// <summary>
        /// 保存任务
        /// </summary>
        /// <param name="task"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        bool SaveTask(TaskModel task, List<TaskAttachmentModel> files);

        /// <summary>
        /// 保存任务操作日志
        /// </summary>
        /// <param name="task"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        bool SaveTaskLog(TaskModel task, string comment);

        /// <summary>
        /// 更新计划是否启用
        /// </summary>
        /// <param name="scheduleJob"></param>
        /// <returns></returns>
        bool UpdateJobInvalid(JobModel job);

        /// <summary>
        /// 更新计划
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        bool UpdateJob(JobModel job);

        /// <summary>
        /// 添加第三方巡检类型
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        bool SaveInspectionType(InspectionType type);

        /// <summary>
        /// 所有责任人为当前登陆用户，状态为进行中且未过期的任务isOverTime = false
        /// 所有责任人为当前登陆用户，状态为进行中且已过期的任务
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="isOverTime"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskByUserID(decimal userID, Nullable<int> pageIndex, Nullable<int> pageSize, out decimal totalCount, bool isOverTime = false, string sort = "ID", string order = "Descending");
        /// <summary>
        /// 所有创建人为当前登陆用户，状态为已完成的任务
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskByCreateUserID(decimal userID, int? pageIndex, int? pageSize, out decimal totalCount, string sort = "JobNo", string order = "Descending");

        /// <summary>
        /// 根据任务位置获取过期的任务(最近一个月的，前后30天)
        /// </summary>
        /// <param name="Location"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="isOverTime">是否过期</param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskByLocation(decimal Location, Nullable<int> pageIndex, Nullable<int> pageSize, out decimal totalCount, bool isOverTime = true, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 获取某个地市今天新增的任务
        /// </summary>
        /// <param name="Location">地市LocationID</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskCreateInToday(decimal Location, Nullable<int> pageIndex, Nullable<int> pageSize, out decimal totalCount, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 获取直到今天还未关闭的任务
        /// </summary>
        /// <param name="Location"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskNotComplete(decimal Location, Nullable<int> pageIndex, Nullable<int> pageSize, out decimal totalCount, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 获取对应年月里面的待办任务
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        Dictionary<string, List<TaskModel>> GetPendingTaskByYearAndMonth(decimal UserID, int year, int month);

        /// <summary>
        /// 当前登陆人创建的计划列表
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        List<JobModel> GetPlanByUserID(decimal userID, int? pageIndex, int? pageSize, out decimal totalCount, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 计划所对应的任务列表
        /// </summary>
        /// <param name="jobID"></param>
        /// <returns></returns>
        List<TaskModel> GetTaskByJobID(decimal jobID, int? pageIndex, int? pageSize, out decimal totalCount, string sort = "JobNo", string order = "Descending");

        /// <summary>
        /// 获取所有的第三方巡检类型
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        List<InspectionType> GetAllInspectionType(out decimal totalCount, Nullable<int> pageIndex, Nullable<int> pageSize, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 删除第三方巡检类型
        /// </summary>
        /// <param name="ID"></param>
        bool DeleteInspectionType(decimal ID);

        #region 巡检对象搜索

        List<T> SearchInspectionObject<T>(out decimal totalCount, InspectionObjectType type, string company, QueryString query, int? pageIndex, int? pageSize, string sort = "Request_ID", string order = "Descending");


        #endregion

        #region 电子公告

        /// <summary>
        /// 获取所有电子公告
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="filterOverTime">是否过滤掉已经过期的</param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<AnnouncementModel> GetAllAnnouncement(out decimal totalCount, Nullable<int> pageIndex, Nullable<int> pageSize, bool filterOverTime = false, string sort = "CreateTime", string order = "Descending");

        /// <summary>
        /// 删除电子公告
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        bool DeleteAnnouncement(decimal ID);

        bool CreateAnnouncement(AnnouncementModel model);

        bool UpdateAnnouncement(AnnouncementModel model);

        AnnouncementModel GetAnnouncementDetail(int ID);

        #endregion

        #region 计划任务搜索
        List<JobViewModel> SearchJob(SearchParam param, out decimal totalCount, int? pageIndex, int? pageSize, string sort = "ID", string order = "Descending");

        List<TaskModel> SearchTask(SearchParam param, out decimal totalCount, int? pageIndex, int? pageSize, string sort = "ID", string order = "Descending");
        #endregion

        /// <summary>
        /// 获取品牌下拉源
        /// </summary>
        /// <returns></returns>
        List<string> GetVendorList();

        /// <summary>
        /// 获取版本下拉源
        /// </summary>
        /// <returns></returns>
        List<string> GetVersionList();

        /// <summary>
        /// 获取用途下拉源
        /// </summary>
        /// <returns></returns>
        List<string> GetUsingList();
        List<string> GetDBVersionList();
        List<string> GetMiddleVersionList();

        #region 计划接口人

        /// <summary>
        /// 获取所有地市和省局
        /// </summary>
        /// <returns></returns>
        List<PlanLocationOwner> GetSiteALLBranch();

        /// <summary>
        /// 获取城市对应的接口人
        /// </summary>
        /// <param name="locationID"></param>
        /// <returns></returns>
        PlanLocationOwner GetInterfacePeopleByLocationID(decimal locationID);

        /// <summary>
        /// 保存计划接口人
        /// </summary>
        /// <param name="ownerID"></param>
        /// <param name="LocationID"></param>
        /// <returns></returns>
        bool SaveInterfacePeople(decimal ownerID, decimal LocationID);

        #endregion

        #region 计划任务组

        /// <summary>
        /// 获取相关地市的所有计划任务组
        /// </summary>
        /// <param name="locationID"></param>
        /// <param name="isGlobalAdmin">是否是省局管理员</param>
        /// <param name="totalCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<PlanGroupModel> GetAllGroup(decimal locationID, bool isGlobalAdmin, out decimal totalCount, int? pageIndex, int? pageSize, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 新建计划任务组
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool SavePlanGroup(PlanGroupModel model);

        /// <summary>
        /// 根据组名获取计划组
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        List<PlanGroupModel> GetGroupByName(string groupName, decimal locationID);

        /// <summary>
        /// 根据ID获取计划组信息
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        PlanGroupModel GetGroupByID(decimal groupID);

        /// <summary>
        /// 更新计划任务组（包含逻辑删除）
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        bool UpdatePlanGroup(PlanGroupModel model);

        /// <summary>
        /// 获取计划组里面的成员
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="totalCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        List<PlanGroupUserModel> GetUsersByGroup(decimal groupID, out decimal totalCount, int? pageIndex, int? pageSize, string sort = "ID", string order = "Descending");

        /// <summary>
        /// 向组里面添加成员
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        bool AddUserIntoGroup(decimal groupID, decimal userID);

        /// <summary>
        /// 同时向组里面添加多个成员
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        bool AddUserListIntoGroup(decimal groupID, List<decimal> users);

        /// <summary>
        /// 从组里面删除某个成员
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        bool DeleteUserFromGroup(decimal groupID, decimal userID);


        /// <summary>
        /// 初始化内置任务组成员
        /// </summary>
        /// <returns></returns>
        bool SyncInternalGroupUser();


        #endregion
    }
}
